package synchronized方法与锁对象;
class MyObjectOne
{
	 public void MethodA() {
		 synchronized (this) {
			 try {
				 System.out.println("begin methodA threadName=" + Thread.currentThread().getName());
				 Thread.sleep(5000);
				 System.out.println("end endTime=" + System.currentTimeMillis());
			 } catch (InterruptedException e) {
				 e.printStackTrace();
			 }
		 }
	 }
	 public void MethodB(){
	synchronized(this) {
		try {
			System.out.println("begin methodB threadName=" + Thread.currentThread().getName() + "BeginTime=" + System.currentTimeMillis());
			Thread.sleep(5000);
			System.out.println("end");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	}
}
class ThreadAA extends Thread{
	private MyObjectOne object;
	public ThreadAA(MyObjectOne object)
	{
		super();
		this.object=object;
	}
	public void run()
	{
		super.run();
		object.MethodA();
	}
}
class ThreadBB extends Thread{
	private MyObjectOne object;
	public ThreadBB(MyObjectOne object)
	{
		super();
		this.object=object;
	}
	public void run()
	{
		super.run();
		object.MethodB();
	}
}
public class Test2_8 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MyObjectOne object=new MyObjectOne();
		ThreadAA aa=new ThreadAA(object);
		aa.setName("A");
		ThreadBB bb=new ThreadBB(object);
		bb.setName("B");
		aa.start();
		bb.start();
		
		
	}

}
